package com.binyouwei.designpatterns.creation_type.singleton;

/**
 * @author 宾有为
 * @date 2024/6/20 19:55
 * @link https://blog.csdn.net/baidu_41616022?type=blog
 * 单例魔兽 —— 懒汉模式（线程不安全版）
 * 优点：第一次调用才初始化，避免内存浪费。
 * 缺点：必须加锁 synchronized 才能保证单例，但加锁会影响效率。
 **/
public class LazyInitialization2 {

    private static LazyInitialization2 instance;

    private LazyInitialization2() {
    }

    public static synchronized LazyInitialization2 getInstance() {
        if (instance == null) {
            instance = new LazyInitialization2();
        }
        return instance;
    }

    public void print() {
        System.out.println("Lazy Initialization 2");
    }
}
